package cn.iocoder.yudao.framework.business.basic.pojo.bo;

import cn.hutool.core.date.LocalDateTimeUtil;
import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
import jakarta.annotation.Nullable;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * <pre>
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 *  这里是文件说明
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * </pre>
 *
 * @author 山野羡民（1032694760@qq.com）
 * @since 2025/05/06
 */
public interface CreateTimeQuery {

    LocalDateTime[] getCreateTime();

    Integer getYear();

    Integer getMonth();

    Integer getDay();

    @Nullable
    default LocalDateTime[] buildCreateTime() {
        Integer year = getYear();
        Integer month = getMonth();
        Integer day = getDay();
        if (year != null && year > 0 && month != null && month > 0) {
            if (day != null && day >= 0) {
                LocalDateTime startTime = LocalDateTimeUtil.beginOfDay(LocalDate.of(year, month, day));
                return new LocalDateTime[]{startTime, startTime.plusDays(1)};
            } else {
                LocalDateTime startTime = LocalDateTimeUtils.beginOfMonth(LocalDateTimeUtil.beginOfDay(LocalDate.of(year, month, 1)));
                return new LocalDateTime[]{startTime, startTime.plusMonths(1)};
            }
        }
        return getCreateTime();
    }

}
